package com.itheima.controller;

import com.itheima.pojo.HmCompanys;
import com.itheima.pojo.IfHmCompanys;
import com.itheima.service.EnterpriseManagementService;
import com.itheima.service.LoginService;
import com.itheima.util.LoginResult;
import com.itheima.util.PageResult;
import com.itheima.util.R;
import com.itheima.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/companys")
public class EnterpriseManagementController {
    @Autowired
    private EnterpriseManagementService enterpriseManagementService;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private LoginService loginService;

    //修改企业管理
    @PutMapping("/{id}")
        public void updateManager(@PathVariable Integer id,@RequestBody HmCompanys hmCompanys) {

        enterpriseManagementService.updateManager(id,hmCompanys);

    }

    //分页查询
    @GetMapping
    public PageResult findByPage(IfHmCompanys ifHmCompanys, Integer page, Integer pagesize) {
        if (null==page){
            return enterpriseManagementService.findAll(pagesize);
        }
        PageResult result = enterpriseManagementService.findByPage(page, pagesize, ifHmCompanys);
        return result;
    }

    //跟据id删除
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable Integer id) {
        enterpriseManagementService.deleteById(id);
    }

    //新建添加企业信息
    @PostMapping
    public R addManager(@RequestBody HmCompanys hmCompanys) {
        R result= enterpriseManagementService.addManager(hmCompanys);
        return result;
    }

    //根据数据修改员工的装态
    @PostMapping("/{id}/{state}")
    public void updateById(@PathVariable Integer id, @PathVariable Integer state) {
        enterpriseManagementService.updateById(id, state);
    }
    @GetMapping("/{id}")
    public HmCompanys findById(@PathVariable Integer id) {

      return  enterpriseManagementService.findById(id);

    }

    /**
     * 试题录入查询所有企业

     */
//    @GetMapping
//    public PageResult findAll(Integer pagesize){
//
//    }

}
